package com.tungse.juc;

import org.junit.Test;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> stringFutureTask = new FutureTask<>(new MyTask());
        new Thread(stringFutureTask).start();
        new Thread(stringFutureTask).start();

        // 等待线程执行完毕，获取返回值
        System.out.println(stringFutureTask.get());
    }
}

class MyTask implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.println("call");
        return "1111";
    }
}